package com.qf.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Description: 公用常量
 * @Data: 2022/9/14 10:45
 * @Pacakge: com.qf.config
 * @ClassName: MyInterceptor
 * @Author: fan
 */
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //获取域对象中存储对象
        HttpSession session = request.getSession();
        Object user = session.getAttribute("user");
        //判断
        if (user != null){
            return true;
        }
        response.sendRedirect("/user/index");
        return false;
    }
}
